package top.hcode.hoj;

import com.zaxxer.hikari.HikariDataSource;
import lombok.SneakyThrows;
import org.sagacity.sqltoy.SqlToyContext;
import top.hcode.hoj.common.LazyDao;
import top.hcode.hoj.tyedu.TyGatewayClient;

import javax.sql.DataSource;

/**
 * @author orangej
 * @since 2025/1/24
 */
public abstract class BaseDbApp {

    @SneakyThrows
    public static DataSource buildDataSource() {
        HikariDataSource dataSource = new HikariDataSource();
        dataSource.setJdbcUrl("jdbc:mysql://rm-bp195r52944zi3t38zo.mysql.rds.aliyuncs.com:3306/hoj?characterEncoding=utf8&useSSL=false&&serverTimezone=Asia/Shanghai");
        dataSource.setUsername("roj_apple");
        dataSource.setPassword("b72-ipN-c8a-EMr");
        return dataSource;
    }

    @SneakyThrows
    public static LazyDao buildLazyDao() {
        SqlToyContext context = new SqlToyContext();
        context.initialize();
//        context.setDebug(true);
        context.setDefaultDataSource(buildDataSource());
        LazyDao lazyDao = new LazyDao();
        lazyDao.setSqlToyContext(context);

        return lazyDao;
    }

    public static TyGatewayClient buildClient() {
        TyGatewayClient client = new TyGatewayClient();
        client.setAppId("D0035E76AE1D7ABE6A5A5E125D555EC1");
        client.setAppKey("191b23c817dc4882b01a8c235b48650d");
        client.setBaseUrl("https://api.wuhaneduyun.cn");

        client.setUniAppId("981944177701683200");
        client.setUniAppSecret("SDSbZ/nL2MvPSDRG85HbnfEqJYVLlyNoT5UaCXOtSdg=");
        client.setUniAppCode("bd9b7da5946448858fb2f8a58c7d03e1");
        return client;
    }
}
